package model;
import java.sql.*;	


public class bddConnection 
{
	// Attributs
	protected Connection connect ;		
	public Statement statement ;		
	
	// Constructeur
	public bddConnection(String server_addr, 
							String bdd_name,
							String bdd_username, 
							String bdd_password)
	{
        try 
        {
    		Class.forName("com.mysql.jdbc.Driver").newInstance();
    		connect = (Connection) DriverManager.getConnection("jdbc:mysql://" 
											    				+ server_addr + "/" 
											    				+ bdd_name + "?user=" 
											    				+ bdd_username + "&password=" 
											    				+ bdd_password +"");
    		statement = (Statement) connect.createStatement();
        } 
        
        catch (Exception ex) 
        {
        	System.out.println("Une erreure est survenue : " + ex);
        }		
	}

	
	// Execute une requete
	public ResultSet doSql(String sqlRequest)
	{
		try
		{
			return statement.executeQuery(sqlRequest);
		}
		
	    catch (Exception ex) 
	    {
	    	System.out.println("Une erreure est survenue : " + ex);
	    	return null;
	    }	
	}
}
